const fs = require('fs')

// 读取文件方法
function readFile(pathStr){
    return new Promise((resolve, reject)=>{
        fs.readFile(pathStr, { flag: 'r', encoding:'utf-8' }, (err, data) => {
            if (err) {
                reject(err);
            }
            resolve(data);
        }); 
    })
}

// 写入文件方法
function writeFile(pathStr, content, flag = 'w') {
    return new Promise((resolve, reject)=>{
        fs.writeFile(pathStr, content, { flag: flag, encoding:'utf-8' }, (err, data) => {
            if (err) {
                reject(err);
            }
            resolve('写入成功');
        }); 
    })
}

module.exports = { readFile, writeFile }